package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.ChainService;
import com.junzhiit.nengji.cms.web.vo.ChainAddVO;
import com.junzhiit.nengji.cms.web.vo.ChainEditVO;
import com.junzhiit.nengji.cms.web.vo.ChainVO;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.ShopVO;
import com.junzhiit.nengji.model.Chain;
import com.junzhiit.nengji.model.WechatConfig;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/chain")
public class ChainController extends BaseController{
	
	@Autowired
	private ChainService chainService;
	
	@ApiOperation(value = "添加连锁品牌")
	@RequestMapping(method=RequestMethod.POST)
	public ResultVO add(ChainAddVO chainAddVO){
		AssertUtil.notBlank(chainAddVO.getSessionId(), "sessionId is required");
		return chainService.add(chainAddVO);
	}
	
	@ApiOperation(value = "修改连锁品牌")
	@RequestMapping(method=RequestMethod.PUT)
	public ResultVO edit(ChainEditVO chainEditVO){
		AssertUtil.notBlank(chainEditVO.getSessionId(), "sessionId is required");
		return chainService.edit(chainEditVO);
	}
	
	@ApiOperation(value = "查询连锁品牌")
	@RequestMapping(method=RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp,ChainVO chainVO){
		return chainService.findAll(dtp, chainVO);
	}
	
	@ApiOperation(value = "品牌连锁店审核")
	@RequestMapping(value = "/audit", method = RequestMethod.POST)
	public ResultVO merchantsAudit(ChainVO chainVO) {
		return chainService.chainAudit(chainVO);
	}
	
	@ApiOperation(value = "查询店铺信息")
	@RequestMapping(value="/{chainId}",method = RequestMethod.GET)
	public ResultVO getById(@PathVariable String chainId) {
		return chainService.findById(chainId);
	}

	@ApiOperation(value = "更新连锁店铺信息")
	@RequestMapping(value = "/update" ,method = RequestMethod.PUT)
	public ResultVO update(ChainVO chainVO) {
		ResultVO result = new ResultVO();
		result.setData(chainService.update(chainVO));
		return result;
	}
	
	@ApiOperation(value = "店铺审核")
	@RequestMapping(value = "/merchants/audit", method = RequestMethod.POST)
	public ResultVO merchantsAudit(ShopVO shopVO) {
		return chainService.merchantsAudit(shopVO);
	}
	
	@ApiOperation(value="获得品牌信息")
	@RequestMapping(value="/session",method=RequestMethod.GET)
	public ResultVO findById(String sessionId){
		AssertUtil.notBlank(sessionId, "sessionId is required");
		return chainService.findBySessionId(sessionId);
	}
	
	@ApiOperation(value = "查询店铺微信配置")
	@RequestMapping(value="/wechat/config",method = RequestMethod.GET)
	public ResultVO getWechatConfig(String sessionId) {
		return chainService.getChainWechatConfig(sessionId);
	}
	
	@ApiOperation(value = "新增或更新微信配置")
	@RequestMapping(value = "/add/or/update", method = RequestMethod.POST)
	public ResultVO addOrUpdateWechatConfig(WechatConfig wechatConfig,String sessionId) {
		return chainService.addOrUpdateWechatConfig(wechatConfig,sessionId);
	}
	
	@ApiOperation(value = "查询连锁品牌List")
	@RequestMapping(value="/list",method = RequestMethod.GET)
	public ResultVO getChainList(Chain chain) {
		return chainService.getChainList(chain);
	}
}
